package online.indigo6a.eshop.controller;

import online.indigo6a.eshop.dto.PageReq;
import online.indigo6a.eshop.dto.PageRes;
import online.indigo6a.eshop.model.CatalogBrand;
import online.indigo6a.eshop.model.CatalogItem;
import online.indigo6a.eshop.model.CatalogType;
import online.indigo6a.eshop.service.CatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/api/v1/catalog")
@RestController
public class CatalogController {
    @Autowired
    private CatalogService catalogService;
    @GetMapping("/items")
    public PageRes<CatalogItem> items(@ModelAttribute PageReq pageReq) {
        Page<CatalogItem> catalogItemList = catalogService.getCatalogItemList(pageReq.toPageRequest());
        PageRes<CatalogItem> res = new PageRes<>();
        res.setData(catalogItemList.getContent());
        res.setPageIndex(catalogItemList.getNumber());
        res.setPageSize(catalogItemList.getSize());
        res.setCount(res.getCount());
        return res;
    }
    @GetMapping("/catalogbrands")
    public Iterable<CatalogBrand> catalogBrands() {
        return catalogService.getCatalogBrandList();
    }
    @GetMapping("/catalogtypes")
    public Iterable<CatalogType> catalogTypes() {
        return catalogService.getCatalogTypeList();
    }
    @PutMapping("/items")
    public void updateProduct() {

    }
    @PostMapping("/items")
    public void createProduct() {

    }
    @DeleteMapping("{id}")
    public void deleteProduct(@PathVariable Integer id) {

    }


}
